﻿Namespace PL.MESSDK

    Public Class LotBOM_PL
        Inherits PLBase
        Implements IPLProcess

        Public Function BatchRecords(dataRow() As System.Data.DataRow) As Boolean Implements IPLProcess.BatchRecords
            Return True
        End Function

        Public Function CurrentRecord(dataRow As System.Data.DataRow) As Boolean Implements IPLProcess.CurrentRecord
            Return True
        End Function
        Public Overrides Function Delete() As Boolean
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            Return True
        End Function

        Public Function NewRecord(dataRow As System.Data.DataRow) As Boolean Implements IPLProcess.NewRecord
            dataRow("LotBOMID") = Guid.NewGuid()
            dataRow("Alternate") = 0
            dataRow("SOP") = String.Empty
            dataRow("Method") = String.Empty
            dataRow("Scaling") = 0
            Return True
        End Function

        Public Overrides Sub ValidateRow(row As DataRow)
            row.ClearErrors()
            'Mandatory Fields
            'TODO: Cache MetaString in AppManager, so here we read it once maybe for nothing
            'Dim ms As MetaString
            'ms = MetaString.GetMetaStringByCode("Mandatory", AppManager.ApplicationOption.LanguageId)

            If IsDBNull(row("LotID_FK")) Then
                row.SetColumnError("LotID_FK", "Mandatory")
            End If

            If IsDBNull(row("WhouseID_FK")) Then
                row.SetColumnError("WhouseID_FK", "Mandatory")
            End If

            If IsDBNull(row("CPrdID_FK")) Then
                row.SetColumnError("CPrdID_FK", "Mandatory")
            End If

            If IsDBNull(row("Target")) Then
                row.SetColumnError("Target", "Mandatory")
            End If

            If IsDBNull(row("UnitID_FK")) Then
                row.SetColumnError("UnitID_FK", "Mandatory")
            End If

            If IsDBNull(row("Alternate")) Then
                row.SetColumnError("Alternate", "Mandatory")
            End If

            If IsDBNull(row("SOP")) Then
                row.SetColumnError("SOP", "Mandatory")
            End If

            If IsDBNull(row("Method")) Then
                row.SetColumnError("Method", "Mandatory")
            End If

            'HACK: Phase out ce champ... remplacer par ScalingId_FK
            If IsDBNull(row("Scaling")) Then
                row.SetColumnError("Scaling", "Mandatory")
            End If

            If IsDBNull(row("ScalingId_FK")) Then
                row.SetColumnError("ScalingId_FK", "Mandatory")
            End If

            If row.HasErrors Then
                row.RowError = "Please check your columns, a validation error occur"
            End If
        End Sub
        ''' <summary>
        ''' Return a Lot DataRow
        ''' </summary>
        ''' <param name="lotBOMID"></param>
        ''' <returns>Return a DataRow when found, Default = Noting</returns>
        ''' <remarks></remarks>
        Public Shared Function GetLotBOMByID(ByVal lotBOMID As Guid) As DataRow
            Dim aRow As DataRow = MetaQuery.GetDataById("LotBOM", lotBOMID)
            Return aRow
        End Function
    End Class
End Namespace
